package com.he.strategymodel.strategy.concretestrategy;

import com.he.strategymodel.strategy.StategyInterface;
import com.he.strategymodel.util.ConfigUtil;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * 满减算法实现
 */
public class SaleStategyReturn implements StategyInterface<Double> {
    /**
     * 满减返还金额map，key满足条件，value到达条件后的返回金额
     */
    static Map<Double, Double> returnCondition = new HashMap<>();

    static {
        String returnCondition1 = ConfigUtil.getValue("returnCondition");
        String[] split = returnCondition1.split(",");
        for (String s : split) {
            String[] split1 = s.split(":");
            returnCondition.put(Double.valueOf(split1[0]), Double.valueOf(split1[1]));
        }
    }


    @Override
    public Double stategy(Double originalMoney) {
        Set<Double> doubles = returnCondition.keySet();
        double returnNum = originalMoney;
        for (Double aDouble : doubles) {
            if (originalMoney > aDouble) {
                returnNum = returnCondition.get(aDouble);
            }
        }
        return returnNum;
    }

    public static void main(String[] args) {
        System.out.println(returnCondition);
    }
}
